<?php include('includes/start.php'); ?>

<?php
$con = mysql_connect($dbserver, $dbuser, $dbpass);
if (!$con)
{
	echo "<p>Connection to server failed</p>";
}
else
{
	mysql_select_db($db, $con);

	$q = fquery($book_query, array($_GET['id']));
	
	$result = mysql_query($q);
	if (mysql_num_rows($result) == 0)
	{
		echo "<p>The requested book does not exist...</p>";
	}
	else
	{
		$row = mysql_fetch_array($result);
		echo "<h2>" . $row['title'] . "</h2>";
		$file = $row['cover_image'];
		echo "<table><tr><td valign='top' id='book_php_img'>";
		if (!file_exists($file))
		{
			echo "<img id='bookimg' src='" . $book_not_found . "' />";
		}
		else
		{
			echo "<a href='" . $row['cover_image'] . "'><div id='bookimgcontainer'><img id ='bookimg' src='" . $row['cover_image'] . "' /></div></a>";
		}
		echo "</td><td valign='top' id='book_php_text'>";
		echo "<p>ISBN: " . $row['isbn'] . "<br /></p>";
		echo "<p>Authors: " . $row['authors'] . "<br /></p>";
		echo "<p>Number of Pages: " . $row['number_of_pages'] . "<br /></p>";
		if ($row['description'])
		{
			echo "<p>Description: " . $row['description'] . "<br /></p>";
		}
		if ($row['format'])
		{
			echo "<p>Format: " . $row['format'] . "<br /></p>";
		}
		if ($row['publisher'])
		{
			echo "<p>Publisher: " . $row['publisher'] . "<br /></p>";
		}
		if ($row['publishing_year'])
		{
			echo "<p>Publishing Year: " . $row['publishing_year'] . "<br /></p>";
		}
		if ($row['edition'])
		{
			echo "<p>Edition: " . $row['edition'] . "<br /></p>";
		}
		if ($row['location'])
		{
			echo "<p>Location: " . $row['location'] . "<br /></p>";
		}
		if ($row['dewey_decimal_number'])
		{
			echo "<p>Dewey Decimal Number: " . $row['dewey_decimal_number'] . "<br /></p>";
		}
		echo "</td></tr></table>";
	}
	echo "<h3>Copies</h3>";
	$q = fquery($book_info_query, array($_GET['id']));
	$result = mysql_query($q);
	echo "<table id='DB_search_results_left'><tr><th>Type</th><th>Checked Out</th></tr>";
	while ($row = mysql_fetch_array($result))
	{
		if ($row['checked_out'])
		{
			$co = "True";
		}
		else
		{
			$co = "False";
		}
		echo "<tr><td>" . $row['name'] . "</td><td>" . $co . "</td></tr>";
	}
	echo "</table>";

	mysql_close($con);
}
?>

<?php include('includes/stop.php'); ?>
